package com.redpack.redpost.struts.action.admin;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.redpack.redpost.struts.form.admin.AgregarComentarioForm;
import com.redpack.redpost.util.dao.ComentarioAdminDao;
import com.redpack.redpost.util.dao.adminDAO;

public class AgregarComentarioVal extends Action {
	
	public ActionForward execute(
			ActionMapping mapping, 
			ActionForm form, 
			HttpServletRequest request, 
			HttpServletResponse response) throws Exception {

		/*boolean logginVal = generalUtil.isLoggedIn(request);
		if(logginVal!=true)
			return mapping.findForward("noLogin") ;*/

	    
		AgregarComentarioForm f = (AgregarComentarioForm)form;
	    if( f.getAcc() != 0 ){
	    	if( !f.getComentario().equals("") ){
	    		ComentarioAdminDao.saveComentario(f.getComentario(), f.getCve_usuario(), 2);

		    	request.setAttribute("save", "1") ;
	    	}else{
	    		request.setAttribute("save", "2") ;
	    	}
	    }
	    
	    if( f.getCve_usuario() > 0 ){
	    	 List comentarios = ComentarioAdminDao.getComentarios(f.getCve_usuario());
	 	    
	 	    request.setAttribute("comentarios", comentarios) ;
	 	   request.setAttribute("cve_usuario", ""+f.getCve_usuario()) ;
	    }
	   

	    return mapping.findForward("success");
	    
	    }

}

